<?php


namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;


class CartDetail extends NotORM
{
    public function getCartDetailInfoByCid($cart_id)
    {
        return $this->getORM()->where('cid', $cart_id)->fetchAll();
    }

    public function insertCartDetailInfo($cart_id, $good_id, $good_num, $good_money)
    {
        $data = array('cid' => $cart_id, 'gid' => $good_id, 'num' => $good_num, 'money' => $good_money);
        $orm = $this->getORM();
        $orm->insert($data);
        return $orm->insert_id();

    }

    public function getCartDetailInfoByCidAndGid($cart_id, $good_id)
    {
        return $this->getORM()->and('cid = ?', $cart_id)->and('gid = ?', $good_id)->fetchAll();
    }

    public function updateCartDetailInfoById($cartDetail_id, $good_num, $good_money)
    {
        $data = array('num' => $good_num, 'money' => $good_money);
        return $this->getORM()->where('id', $cartDetail_id)->update($data);
    }

    public function deleteCartDetailInfoByCid($cart_id)
    {
        return $this->getORM()->where('cid', $cart_id)->delete();
    }
}